package com.itheima.Object;

import java.io.*;
import java.util.ArrayList;

public class prac01 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //对于多个自定义对象进行序列化操作和反序列化操作
       //进行序列化
        //method();

        //进行反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("20240417\\a.txt"));
        ArrayList<Student>  o = (ArrayList<Student> )ois.readObject();
        for (Student student : o) {

            System.out.println(student);
        }
        ois.close();
    }

    private static void method() throws IOException {
        Student s1 = new Student("zhangsan",23,"南京");
        Student s2 = new Student("lisi",24,"重庆");
        Student s3 = new Student("wangwu",25,"北京");

        ArrayList<Student>list=new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //将学生对象集合进行序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("20240417\\a.txt"));
        oos.writeObject(list);
        oos.close();
    }
}
